package com.林子祺.CAT旅游系统.view.tour.admin;

import com.林子祺.CAT旅游系统.controller.contentmanagement.Admin;
import com.林子祺.CAT旅游系统.controller.contentmanagement.ShowTicket;
import com.林子祺.CAT旅游系统.dao.login.PullAccount;
import com.林子祺.CAT旅游系统.dao.placemanagement.PlacePull;
import com.林子祺.CAT旅游系统.dao.ticketmanagement.TicketPull;
import com.林子祺.CAT旅游系统.dao.ticketmanagement.TicketPull4;
import com.林子祺.CAT旅游系统.entity.login.UserData;
import com.林子祺.CAT旅游系统.entity.place.PlaceData;
import com.林子祺.CAT旅游系统.entity.ticket.TicketData;
import com.林子祺.CAT旅游系统.view.Menu;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;

public class AdminMenu {

    public static void menu(){
        JFrame jf = new JFrame("管理员界面");
        jf.setSize(450, 450);
        jf.setLocationRelativeTo(null);
        jf.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

        JPanel panel = new JPanel(null);

        JButton btn1 = new JButton("返回");
        btn1.setLocation(0,0);
        btn1.setSize(100,30);
        btn1.setFont(new Font(null, Font.PLAIN, 10));
        btn1.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                try {
                    Menu.menu();
                } catch (AWTException awtException) {
                    awtException.printStackTrace();
                }
                jf.dispose();
            }
        });
        panel.add(btn1);

        JButton btn = new JButton("删除景点");
        btn.setLocation(0,30);
        btn.setSize(100,30);
        btn.setFont(new Font(null, Font.PLAIN, 10));
        btn.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                InsertDeletePlace.delete();
                jf.dispose();
            }
        });
        panel.add(btn);

        JButton btn2 = new JButton("修改景点");
        btn2.setLocation(0,60);
        btn2.setSize(100,30);
        btn2.setFont(new Font(null, Font.PLAIN, 10));
        btn2.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                PlaceData.Refresh();
                PlacePull.pull();
                InsertChangePlace.change();
                jf.dispose();
            }
        });
        panel.add(btn2);

        JButton btn3 = new JButton("删除门票");
        btn3.setLocation(0,90);
        btn3.setSize(100,30);
        btn3.setFont(new Font(null, Font.PLAIN, 10));
        btn3.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                TicketData.Refresh();
                TicketPull4.pull();
                InsertDeleteTicket.delete();
                jf.dispose();
            }
        });
        panel.add(btn3);

        JButton btn4 = new JButton("修改门票");
        btn4.setLocation(0,120);
        btn4.setSize(100,30);
        btn4.setFont(new Font(null, Font.PLAIN, 10));
        btn4.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                TicketData.Refresh();
                TicketPull4.pull();
                InsertChangeTicket.change();
                jf.dispose();
            }
        });
        panel.add(btn4);

        JButton btn5 = new JButton("增加景点");
        btn5.setLocation(0,150);
        btn5.setSize(100,30);
        btn5.setFont(new Font(null, Font.PLAIN, 10));
        btn5.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                AddPlace.update();
                jf.dispose();
            }
        });
        panel.add(btn5);

        JButton btn6 = new JButton("增加门票");
        btn6.setLocation(0,180);
        btn6.setSize(100,30);
        btn6.setFont(new Font(null, Font.PLAIN, 10));
        btn6.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                AddTicket.update();
                jf.dispose();
            }
        });
        panel.add(btn6);

        JButton btn7 = new JButton("删除用户");
        btn7.setLocation(0,210);
        btn7.setSize(100,30);
        btn7.setFont(new Font(null, Font.PLAIN, 10));
        btn7.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                UserData.ud = new ArrayList<>();
                PullAccount.pull();
                DeleteAccount.delete();
                jf.dispose();
            }
        });
        panel.add(btn7);

        jf.setContentPane(panel);
        jf.setVisible(true);
    }

}
